<?php

class App_Helper_Menu_Menu {
   
   public $type;
   private $_menuitems;
   private $_wrapElem;
   private $_containerElement;
   private $_containerId;
   private $_dropDownElement;
   private $_dropDownId;   
   
   public function __construct($menuitem=null, $submenuitems=array(),$containerId='menu-container', $dropDownId='drop_down_menu') {
    
      $this->_containerElement = 'div';
      $this->_dropDownElement = 'ul';
      $this->_wrapElem = 'li';
      if($menuitem) {
         $this->add($menuitem, $submenuitems);
      }
      
   }
   
   public function add($menuitem, $subMenuItems=array()) {
      $menuitem->setWrapElement($this->_wrapElem);
      if(is_array($subMenuItems) && count($subMenuItems) > 0) {
         $menuitem->subMenuItems = $subMenuItems;  
      }
      $this->_menuitems[] = $menuitem;
   }
   
   public function __toString() {
      $str = "";
      $view = Zend_Layout::getMvcInstance()->getView();      
      foreach($this->_menuitems as $menuitem) {
         if(count($menuitem->subMenuItems)) {
            $str .= "<li class=\"$menuitem->menuItemClass\">";
            if($menuitem->link) {
               $menuitem->wrap = false;
               $menuitem->title = $view->translate->_($menuitem->title);
               $str .= $menuitem;
            } else {
               $str .= $view->translate->_($menuitem->title);
            }
            
            $str .= "<ul class=\"$menuitem->subMenuContainerClass\">";
            
            foreach($menuitem->subMenuItems as $submenuitem) {
               $str .= $submenuitem;
            }
            
            $str .= "</ul>
            </li>";
         } else {
            $str .= $menuitem;
         }
      }
      
      return $str;
   }
}

